<template>
    <div>
        <h5>外部调用接口记录</h5>
        <sky-table :data="tableData" :columns="columns" :show-index="true" :show-pagination="true"></sky-table>
    </div>
</template>


<style scoped>
</style>


<script>
import Axios from "axios"

function padLeftZero (str) {
    return ('00' + str).substr(str.length);
};

function formatDate (longStr, fmt) {
   let date = new Date(longStr);

    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
    }
    let o = {
        'M+': date.getMonth() + 1,
        'd+': date.getDate(),
        'h+': date.getHours(),
        'm+': date.getMinutes(),
        's+': date.getSeconds()
    };
    for (let k in o) {
        if (new RegExp(`(${k})`).test(fmt)) {
            let str = o[k] + '';
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str));
        }
    }
    return fmt;
};

export default {
    name: "OriginOuterLog",
    data: () => ({
        columns: [
            {
                title: "执行用户",
                key: "userName"
            },
            {
                title: "所属项目",
                key: "projectName"
            },
            {
                title: "执行日期",
                key: "callTime",
                render: (h,params) => {
                    // console.log(params);
                    let fmtDate = formatDate(params.row.callTime,'yyyy-MM-dd hh:mm:ss')
                    return (
                        <div>
                            {fmtDate}
                        </div>
                    );
                }
            },
            {
                title: "调用结果",
                key: "status",
                align: "center",
                render: h => {
                    let vm = this;
                    return (
                        <div style="color:  #19be6b;">
                            <i
                                class="fas fa-check-circle mr-1"
                                style="color:  #19be6b;"
                            />调用成功
                        </div>
                    );
                }
            }
        ],
        tableData: []
    }),
    created: function() {
        let self = this;

        let url = "/app/v1/apis/"+this.$route.query.oid+"/outCalls?pageSize="+1000;

        self.$http.get(url).then(res => {
            console.log(res);                
            self.tableData = res.data.data;
        });

    }
};
</script>
